package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/6/6 15:52
 * https://leetcode.cn/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/
 */
public class Title46 {

    /**
     * dp[i]表示[0,i]时翻译的方法个数
     * @param num
     * @return
     */
    public static int translateNum(int num) {
        char[] s = String.valueOf(num).toCharArray();
        int n = s.length;
        //dp[0]不用，模拟
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            int count = (s[i - 2] - '0') * 10 + (s[i - 1] - '0');
            if (count <= 25 && count >= 10) {
                //当值为[10, 25]可以跳阶梯，一次可以跳两个阶梯
                dp[i] = dp[i - 1] + dp[i - 2];
            } else {
                dp[i] = dp[i - 1];
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        translateNum(11);
    }
}
